import * as apis from '../services/policyService.js'

export default {
    namespace: "policy",
    state: {
        toolHtml:""
    },
    reducers: {
        setToolHtml:setToolHtml
    },
    effects: {
        getToolHtml: getToolHtml,
        repairToolHtml:repairToolHtml
    }
}

function setToolHtml(state,payload){
    let _state = JSON.parse(JSON.stringify(state));
    _state.toolHtml = payload.data
    return _state
}

/**
 * 获取模型工具外部链接
 */
function* getToolHtml(payload, { select, call, put }) {
    let result = yield call(apis.getToolHtml)

    yield put({
        type:"policy/setToolHtml",
        data:result.data.data
    })
   
}

/**
 * 修改模型工具外部链接
 */
function* repairToolHtml(payload, { select, call, put }) {
    let result = yield call(apis.repairToolHtml, payload.data)

    if(result.data.code){
        yield put({
            type:"policy/getToolHtml",
        })
    }
}